package com.atguigu.gulimall.search.controller;


import com.atguigu.gulimall.search.service.MallSearchService;
import com.atguigu.gulimall.search.vo.SearchParam;
import com.atguigu.gulimall.search.vo.SearchResult;
import org.bouncycastle.cms.PasswordRecipient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Controller

public class SearchController {


    @Autowired
    private MallSearchService mallSearchService;

    @GetMapping ("/list.html")
    public String listPage(SearchParam searchParam, Model model, HttpServletRequest request){


        String queryString = request.getQueryString(); //  获取参数


        searchParam.set_queryString(queryString); // 赋值


        SearchResult search = mallSearchService.search(searchParam);  //去elasticSearch查询结果


        model.addAttribute("result",search);//把 结果   放在 作用域中


        return  "list";
    }



}
